﻿Public Class Buscar_CDs
    Dim datos_clase As New datos

    Private Sub cargarCds()
        Dim conexion As New SqlClient.SqlConnection
        Dim cmd As New SqlClient.SqlCommand
        Dim data As New Data.DataTable
        conexion.ConnectionString = datos_clase._cadena
        conexion.Open()
        cmd.Connection = conexion
        cmd.CommandType = CommandType.Text
        Dim sql As String = "SELECT cd.codigo_cd , cd.titulo, cd.precio_venta, genero.nombre FROM (cd INNER JOIN genero on cd.id_genero = genero.id_genero)"
        cmd.CommandText = sql
        data.Load(cmd.ExecuteReader())
        conexion.Close()
        Dim fila As Integer = 0

        DataGridView1.Rows.Clear()

        For fila = 0 To data.Rows.Count - 1
            DataGridView1.Rows.Add()
            DataGridView1.Rows(fila).Cells(0).Value = data.Rows(fila)(0)
            DataGridView1.Rows(fila).Cells(1).Value = data.Rows(fila)(1)
            DataGridView1.Rows(fila).Cells(2).Value = data.Rows(fila)(2)
            DataGridView1.Rows(fila).Cells(3).Value = data.Rows(fila)(3)
        Next
    End Sub

    Private Sub Buscar_CDs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cargarCds()
    End Sub


    Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        Dim condicion As String = "codigo_cd = '" & DataGridView1.CurrentRow.Cells(0).Value & "'"
        Dim tabla As Data.DataTable = datos_clase.leo_tabla("cd", condicion)

        Factura.txt_codigo_cd.Text = tabla.Rows(0)(0)
        Factura.txt_titulo_cd.Text = tabla.Rows(0)(1)
        Factura.txt_precio_cd.Text = tabla.Rows(0)(2)

        Me.Close()
    End Sub

    Private Sub btn_salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_salir.Click
        Me.Close()
    End Sub
End Class